<!DOCTYPE html>
<html>
<head>
<script src="./js/jquery-1.10.2.min.js"> </script>
<style type="text/css">
.bool-slider 
{
         border: 1px solid #CCC;
    color: #FFF;
    font-size: 18px;
    font-weight: 800;
    font-family: Helvetica, Verdana, Arial, sans-serif;
    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
    
    height: 35px;
    width: 100px;
    border-radius: 25px;
}

.bool-slider.true .inset
{
    background-color: #51a351;
        *background-color: #499249;
    background-image: linear-gradient(top, #62c462, #51a351);
    background-repeat: repeat-x;
    border-color: #51a351 #51a351 #387038;
    border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
        background-image: none;
      box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
}
.bool-slider.true .inset .control{float: left;}
.bool-slider.true .inset .control:after
{
    content: 'On';
    position: relative;
    right: -135%;
    top: 20%;
}

.bool-slider.false .inset
{
    background-color: #da4f49;
    *background-color: #bd362f;
    background-image: linear-gradient(top, #ee5f5b, #bd362f);
    background-repeat: repeat-x;
    border-color: #bd362f #bd362f #802420;
        border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
        background-image: none;
      box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
}
.bool-slider.false .inset .control{float: right;}
.bool-slider.false .inset .control:before
{
    content: 'Off';
    position: relative;
    left: -100%;
    top: 20%;
}

.bool-slider .inset
{
    width: 100%;
    height: 100%;
    border-radius: 20px;
    
}

.bool-slider .inset .control
{
    background-color: #000;
    width: 40%;
    height: 100%;
    border-radius: 20px;
    background-color: #f5f5f5;
    *background-color: #e6e6e6;
    background-image: linear-gradient(top, #ffffff, #e6e6e6);
    background-repeat: repeat-x;
}

.bool-slider .inset .control:hover
{
    cursor: pointer;
}

.bool-slider.disabled
{
    color: #CCC;
}

.bool-slider.disabled .inset
{
  background-color: #f5f5f5;
  *background-color: #e6e6e6;
  background-image: linear-gradient(top, #ffffff, #e6e6e6);
  background-repeat: repeat-x;
}

.bool-slider.disabled .control
{
    cursor: default;
}
</style>

<script>
$(document).ready(function() {
    $('.bool-slider .inset .control').click(function() {
	
        if (!$(this).parent().parent().hasClass('disabled')) {
            if ($(this).parent().parent().hasClass('true')) {
                $(this).parent().parent().addClass('false').removeClass('true');
				$("#led").attr("src","img/on.png");
				$.ajax({
						url: './ajax/arduino_led_on.php',
						success: function(data) {
						 $("#status").text(data);
						 //alert('LED ON');
						 //read();
						}
				});
            } else {
                $(this).parent().parent().addClass('true').removeClass('false');
				$("#led").attr("src","img/off.png");
				$.ajax({
						url: './ajax/arduino_led_off.php',
						success: function(data) {
						 $("#status").text(data);
						  //alert('LED OFF');
						  //read();
						}
				});				
            }
            
	    
        }
    });
});
function read()
{
	$.ajax({
		      url: './ajax/arduino_led_estado.php',
		      success: function(data) {
			alert("."+data.trim()+".");
			if(data.trim()=='0')
			{
			  $("#status").text("Apagado");
			}
			
			if(data.trim()=='1')
			{
			  $("#status").text("Encendido");
			}
			
		      }
	});
}
</script>
</head>

<body>
<img id="led" src="img/off.png">
<div class="bool-slider true">
    <div class="inset">
        <div class="control"></div>
    </div>
</div>
<div id="status">aa</div>


</body>
</html>


